package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.SysDocument;
import com.sale.system.domain.dto.SysDocumentDto;
import com.sale.system.service.ISysDocumentService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


/**
 * @Description 单据配置
 * @Param
 * @return 结果
 * @Date 22-11-22
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/document")
public class SysDocumentController extends BaseController {

    private final ISysDocumentService sysDocumentService;

    /**
     * 获取单据配置
     */
    //@SaCheckPermission("system:billconfig:list")
    @GetMapping("/list")
    public TableDataInfo<SysDocumentDto> list(SysDocument sysDocument, PageQuery pageQuery)
    {
        return sysDocumentService.selectDocumentList(sysDocument,pageQuery);
    }

    /**
     * 根据id查询详情
     */
    //@SaCheckPermission("system:billconfig:query")
    @GetMapping(value = "/{docId}")
    public R<Map<String, Object>> getInfo(@PathVariable long docId) {
        Map<String, Object> ajax = new HashMap<>();
        ajax.put("sysDocument",sysDocumentService.selectDocumentListById(docId));
        return R.ok(ajax);
    }

    /**
     * 删除单据配置
     */
    //@SaCheckPermission("system:billconfig:remove")
    @Log(title = "编码配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{docId}")
    public  R<Void> remove(@PathVariable("docId") String docId){
        return toAjax(sysDocumentService.deleteDocumentById(docId));
    }

    /**
     * 新增单据配置
     */
    //@SaCheckPermission("system:billconfig:add")
    @Log(title = "编码配置", businessType = BusinessType.INSERT)
    @PostMapping
    public  R<Void> add(@Validated @RequestBody SysDocument sysDocument) {
        return toAjax(sysDocumentService.insertDocument(sysDocument));
    }

    /**
     * 修改单据配置
     */
    //@SaCheckPermission("system:billconfig:edit")
    @Log(title = "编码配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public  R<Void> edit(@Validated @RequestBody SysDocument sysDocument) {
        return toAjax(sysDocumentService.updateDocument(sysDocument));
    }


    /**
     * 根据权限码返回生成编码
     * 远程调用接口
     */
    @GetMapping(value = "/authorityCoding")
    public String authorityCoding(String docConfig) {
        return sysDocumentService.selectAuthorityCoding(docConfig);
    }

    /**
     * 根据配置单据查询单据配置详情
     * 远程调用接口
     */
    @GetMapping(value = "/docConfigById/{docConfig}")
    public R<SysDocument> getInfoConfig(@PathVariable Long docConfig) {
        return R.ok(sysDocumentService.selectDocumentConfigById(docConfig));
    }

}
